package com.jxnu.duewang.zmly.zouZhen.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jxnu.duewang.zmly.BR;
import com.jxnu.duewang.zmly.R;
import com.jxnu.duewang.zmly.zouZhen.model.DatabindingDiscoverSpecialColumn;

import java.util.List;

/**
 * Project Zmly
 * Author Duewang
 * Time 2016/12/9 0009
 */

public class DiscoverSpecialColumnRecycleViewAdapter extends RecyclerView.Adapter<DiscoverSpecialColumnRecycleViewAdapter.BindingViewHolder> {

    private Context mContext;
    private List<DatabindingDiscoverSpecialColumn> mDatabindingDiscoverColumnList;

    public DiscoverSpecialColumnRecycleViewAdapter(Context context, List<DatabindingDiscoverSpecialColumn> databindingDiscoverColumnList) {
        mContext = context;
        mDatabindingDiscoverColumnList = databindingDiscoverColumnList;
    }

    @Override
    public BindingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewDataBinding ret = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.discover_special_column, parent, false);
        return new BindingViewHolder(ret);
    }

    @Override
    public void onBindViewHolder(BindingViewHolder holder, int position) {
        DatabindingDiscoverSpecialColumn databindingDiscoverSpecialColumn = mDatabindingDiscoverColumnList.get(position);
        if(position==0){
            databindingDiscoverSpecialColumn.setTitleFlag(true);
            databindingDiscoverSpecialColumn.setBottomFlag(false);
        }else if(position==mDatabindingDiscoverColumnList.size()-1){
            databindingDiscoverSpecialColumn.setTitleFlag(false);
            databindingDiscoverSpecialColumn.setBottomFlag(true);
        }else {
            databindingDiscoverSpecialColumn.setTitleFlag(false);
            databindingDiscoverSpecialColumn.setBottomFlag(false);
        }
        holder.binding.setVariable(BR.specialColumn,databindingDiscoverSpecialColumn);
    }

    @Override
    public int getItemCount() {
        int ret=0;
        if (mDatabindingDiscoverColumnList != null) {
            ret=mDatabindingDiscoverColumnList.size();
        }
        return ret;
    }

    static class BindingViewHolder extends RecyclerView.ViewHolder{
        private final ViewDataBinding binding;
        BindingViewHolder(ViewDataBinding binding){
            super(binding.getRoot());
            this.binding=binding;
        }
    }

}
